package com.erp.servlet;

import com.erp.service.OrderService;
import com.erp.util.factroy.ObjectFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lpy
 * 订单状态控制器
 */
@WebServlet("/orederstateedit.action")
public class OrederStateEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrderService orderService = ObjectFactory.getServiceInstance("com.erp.service.impl.OrderServiceImpl",OrderService.class);
        //获取订单编号
        String oid = req.getParameter("oid");
        String type = req.getParameter("type");
        if ("cancel".equals(type)){
            //修改订单状态为已取消
            orderService.updateBatch(10,oid);
        }else if ("purchase".equals(type)){
            //修改订单状态为已采购
            orderService.updateBatch(6,oid);
        }else if ("batchpurchase".equals(type)){
            //获取批量处理的订单编号参数,按“，”拆分成数组
            String[] oids = req.getParameter("oids").split(",");
            //批量修改为已采购
            orderService.updateBatch(6,oids);
            try {
                Thread.sleep(1200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //转发到订单列表控制器
        req.getRequestDispatcher("orderlist.action").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
